screenNum=0;
res=[640 480];
clrdepth=32;
[wPtr, rect]=Screen('OpenWindow', screenNum, 0, [0 0 res(1) res(2)], clrdepth);

black=BlackIndex(wPtr);
white=WhiteIndex(wPtr);
Screen('FillRect', wPtr, black);

refresh = Screen('GetFlipInterval', wPtr)
vbl = Screen('Flip', wPtr);


tic
for i=1:30
    
    %2 refresh cycles
    if mod(i,2)==0
        Screen('FillRect',wPtr,black);
    else
        Screen('DrawText', wPtr, white);
    end;
    vbl = Screen('Flip', wPtr, vbl+ (2 - 0.1) * refresh);
end;

toffset = Screen('Flip', wPtr, vbl + (2-0.5) * refresh);
toc


image2D = 255*rand(500,500);
 textureIndex = Screen('MakeTexture', wPtr, image2D);
 Screen('DrawTexture', wPtr, textureIndex);
 Screen('Flip', wPtr);

tic
while toc<3
    
end
toc


Screen('CloseAll');


